#!/bin/bash

DIR="$(dirname "$0")"
VARGUID="FFF12B8D-7696-4C8B-A985-2747075B4F50"
NVARGUID="CEF5B9A3-476D-497F-9FDC-E98143E0422C"
base=""
base_0x=""
size=""
end=""
varpath="./var"
count=0

if [ -f "$DIR/Layout" ];then
  rm $DIR/Layout
fi

for file in "$varpath"/*
do

  while read line
  do
    
    if [[ $line =~ "Base:" ]] ; then
      #echo $line
      base=`echo $line | awk -F": " '{print $2}' | awk -F"h" '{print $1}' `
      base_0x=0x${base}
      #echo $base_0x
    elif [[ $line =~ "Full size:" ]] ; then
      #echo $line
      size=`echo $line | awk -F": " '{print $2}' | awk -F"h" '{print $1}' `
      size=0x${size}
      #echo $size
    fi
  done < $file

  end=$((${base_0x} + ${size} - 1))
  #end=`echo "obase=16;${end}"|bc`
  end=`printf "%X" ${end}`

  #end=0x${end}
  #echo 0x$end
  echo ${base}:${end} NVFV$count >> $DIR/Layout
  FlashName=$FlashName"-i NVFV$count "
  count=$(expr $count + 1)

done
echo $FlashName
#rm -rf *.bin

